//
//  TabBarViewViewController.m
//  DayDayRun
//
//  Created by 卫建 on 16/1/6.
//  Copyright © 2016年 卫建. All rights reserved.
//

#import "TabBarViewController.h"
#import "RunViewController.h"
#import "MyViewController.h"
#import "SportCircleViewController.h"
#import "XZMTabbarExtension.h"

@interface TabBarViewController ()

@end

@implementation TabBarViewController

+(void)initialize
{
    //设置apprenece设置所有文字属性
    UITabBarItem *tabBarItem = [UITabBarItem appearance];
    
    //设置默认状态
    NSMutableDictionary *defDic = [NSMutableDictionary dictionary];
    defDic[NSFontAttributeName] = [UIFont systemFontOfSize:14];
    defDic[NSForegroundColorAttributeName] = [UIColor colorWithRed:0.3965 green:0.5081 blue:0.4316 alpha:1.0];
    [tabBarItem setTitleTextAttributes:defDic forState:UIControlStateNormal];
    
    //设置选中状态
    NSMutableDictionary *selDic = [NSMutableDictionary dictionary];
    selDic[NSFontAttributeName] = defDic[NSFontAttributeName];
    selDic[NSForegroundColorAttributeName] = [UIColor colorWithRed:0.1679 green:0.7049 blue:0.0576 alpha:1.0];
    [tabBarItem setTitleTextAttributes:selDic forState:UIControlStateSelected];
}


- (void)viewDidLoad
{
    [super viewDidLoad];
    
    //执行添加控制器的方法
    [self addChildController];
    
    
    

}

//添加tabBar上面每一个tabBarItem对应的每一个控制器
-(void)addChildController
{
    SportCircleViewController *sportVC = [[SportCircleViewController alloc]init];
    RunViewController *runVC = [[RunViewController alloc]init];
    MyViewController *myVC = [[MyViewController alloc]init];
    
    
    [self setUpChildControllerWith:sportVC defImage:[UIImage imageNamed:@""]selImage:[UIImage imageNamed:@""] title:@"运动圈"];
    
    
    
    //设置中间按钮
    [self.tabBar setUpTabBarCenterButton:^(UIButton * _Nullable centerButton) {
        
        [centerButton setBackgroundImage:[UIImage imageNamed:@"health_data_icon_run"] forState:UIControlStateNormal];
        [centerButton setBackgroundImage:[UIImage imageNamed:@"health_data_icon_run"] forState:UIControlStateSelected];
        
//        [centerButton addTarget:self action:@selector(clickedCenterButton:) forControlEvents:UIControlEventTouchUpInside];

//        UINavigationController *runNC = [[UINavigationController alloc]initWithRootViewController:runVC];
        [self setUpChildControllerWith:runVC defImage:[UIImage imageNamed:@""] selImage:[UIImage imageNamed:@""] title:@""];

        
    }];
    
    [self setUpChildControllerWith:myVC defImage:[UIImage imageNamed:@""] selImage:[UIImage imageNamed:@""] title:@"我的"];
        
}

#pragma mark---------配置子视图控制器的tabBaritem的方法
-(void)setUpChildControllerWith:(UIViewController *)childVC
                       defImage:(UIImage *)defImage
                       selImage:(UIImage *)selImage
                          title:(NSString *)title
{
    UINavigationController *childNC = [[UINavigationController alloc]initWithRootViewController:childVC];
    childVC.title = title;
    childVC.tabBarItem.image = defImage;
    childVC.tabBarItem.selectedImage = selImage;
    
    [self addChildViewController:childNC];
}

#pragma mark-------配置centerButton按钮的方法



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}



@end
